"""
迭代器：
1. 实现了__iter()__方法的类，创建的对象叫做"可迭代对象"
2. 实现了 __iter()__、__next()__方法的类，创建的对象就是"迭代器对象"
3. __iter()__方法返回迭代器对象的引用
"""
import time
from collections.abc import Iterable  # 可迭代
from collections.abc import Iterator  # 迭代器


class Test(object):
    pass


class Test2(object):
    def __iter__(self):
        return self

    def __next__(self):
        return 100


t = Test()
t2 = Test2()

# 使用isinstance()来判断是否是可迭代、迭代器对象
print(isinstance(t, Iterable))
print(isinstance(t, Iterator))

print(isinstance(t2, Iterable))
print(isinstance(t2, Iterator))

t2_iter = iter(t2)
# print(next(t2_iter))
# print(next(t2_iter))
# print(next(t2_iter))
# print(next(t2_iter))
# print(next(t2_iter))

for x in t2:
    print(x)
    time.sleep(1)
